/**
 * 登录状态显示
 */
request({
	url: 'data/global/user.json',
	success:function(data) {
		if (data.loggedIn) { //已登录
			$('#loggedIn').show();
			var user = data.user,
				assets = user.assets,
				total = thousandth(assets.total),
				demical = demicalFormat(assets.total,2),
				wealth = thousandth(assets.wealth),
				credit = thousandth(assets.credit),
				score = thousandth(assets.score);
				

			// 头像
			$('#avatar').prop('src',user.avatar);
			// 姓名
			$('#name').text(user.name);
			// 总资产
			$('#total')
				.attr('total',total +'<span>.'+ demical +'</span>')
				.html(total +'<span>.'+ demical +'</span>');
			// 财富分
			$('#wealth')
				.attr('wealth',wealth)
				.text(wealth);
			// 信用分
			$('#credit')
				.attr('credit',credit)
				.text(credit);
			// 积分
			$('#score')
				.attr('score',score)
				.text(score);

		} else { // 未登录
			$('#notLoggedIn').show();
		}
	}

});


/**
 * 显示隐藏数字
 */
// 显示状态，默认为显示
var visible = true;
$('#eye').on('click',function() {
	if (visible) {
		$('#total').html('****');
		$('#wealth').text('****');
		$('#credit').text('****');
		$('#score').text('****');
	} else {
		$('#total').html($('#total').attr('total'));
		$('#wealth').text($('#wealth').attr('wealth'));
		$('#credit').text($('#credit').attr('credit'));
		$('#score').text($('#score').attr('score'));
	}

	// 切换状态
	visible = !visible;
});



/**
 * 广告栏
 */
request({
	url: 'data/home/adv.json',
	success: function(data) {
		var $adv = $('#adv a');
		$adv.prop('href',data.page)
			.find('img')
			.prop('src',data.pic);
	}
});


$('#goInfoList').on('click',function{
	location.href = 'info-list.html';
});


